package com.yb.guigu.pick.security.encoder;

import com.yb.guigu.pick.core.constant.EncryptType;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/6/3 17:41
 * FileName: GuiguPasswordEncoder
 * Description:
 */

@Component
public class GuiguBcryptPasswordEncoder implements GuiguPasswordEncoder {
    private final BCryptPasswordEncoder bCryptPasswordEncoder=new BCryptPasswordEncoder();

    @Override
    public boolean support(String encryptedType) {
        return EncryptType.BCRYPT.getEncryptedType().equals(encryptedType);
    }


    @Override
    public String encode(CharSequence rawPassword) {
        return bCryptPasswordEncoder.encode(rawPassword);
    }


    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return bCryptPasswordEncoder.matches(rawPassword, encodedPassword);
    }
}
